package day13.edu;
// Created: 13/09/2025, ChangJiang Ru

/**
 * Description: Using the extends class of Thread to achieve the sale ticket
 */
public class WindowTest1 {
    public static void main(String[] args) {
        int ticket = 100;

        Window w1 = new Window();
        Window w2 = new Window();
        Window w3 = new Window();

        w1.setName("Thread 1");
        w2.setName("Thread 2");
        w3.setName("Thread 3");

        w1.start();
        w2.start();
        w3.start();
    }
}

class Window extends Thread
{
    static int ticket = 100;

    @Override
    public void run()
    {
        while(true)
        {
            if(ticket > 0)
            {
                try {
                    Thread.sleep(10);
                }catch(InterruptedException e)
                {
                    e.printStackTrace();
                }

                System.out.println(Thread.currentThread().getName() + " have sale, the number is : " + ticket);
                ticket--;
            }else
            {
                break;
            }
        }
    }
}
